<?php Yii::app()->clientScript->registerCoreScript('cookie'); ?>
<div class="wide form">

    <?php
    $form = $this->beginWidget('CActiveForm', array(
        'id' => 'validation-form',
        'action' => Yii::app()->createUrl($this->route),
        'method' => 'get',
            ));
    ?>

    <div class="row">
        <?php echo $form->label($model, 'Ticker:'); ?>
        <?php echo $form->dropDownList($model, 'companyID', $model->getAllCompany('All')); ?>
        <?php echo CHtml::label('From: ', 'fromDate', array('class' => 'labelForDate')); ?>
        <?php
        $this->widget('zii.widgets.jui.CJuiDatePicker', array(
            'name' => 'from',
            // additional javascript options for the date picker plugin
            'options' => array(
                'showAnim' => 'fold',
                'dateFormat' => 'dd/mm/yy',
                'changeMonth' => true,
                'changeYear' => true,
                'yearRange' => '-20:+20',
            ),
            'htmlOptions' => array(
                'id' => 'fromDate'
            ),
        ));
        ?>
        <?php echo CHtml::label('To: ', 'toDate', array('class' => 'labelForDate')); ?>
        <?php
        $this->widget('zii.widgets.jui.CJuiDatePicker', array(
            'name' => 'to',
            // additional javascript options for the date picker plugin
            'options' => array(
                'showAnim' => 'fold',
                'dateFormat' => 'dd/mm/yy',
                'changeMonth' => true,
                'changeYear' => true,
                'yearRange' => '-20:+20',
            ),
            'htmlOptions' => array(
                'id' => 'toDate'
            ),
        ));
        ?>
    </div>
    <div class="row">
        <?php echo CHtml::submitButton('Search', array('id' => 'btSearch')); ?>
        <?php echo CHtml::submitButton('Start Validation', array('id' => 'btValidate')); ?>
        <?php echo CHtml::label('Status:', 'status'); ?>
        <span id="status">Done</span>
    </div>
    <?php $this->endWidget(); ?>

</div><!-- search-form -->
<!-- Js code for Validate function -->
<script type="text/javascript">
    //Click handler for Validate button
    $('#btValidate').click(function() {
        $.cookie('isValidating', 1);
        $('#status').text('Validating...');
        return true;
    });
    $('#btSearch').click(function() {
        $.cookie('isValidating', 0);
        $('#status').text('Searching...');
        return true;
    });
    
    //This function's used to show which cell has an error
    function showErrors(data) {
        //alert(data);
        data = JSON.parse(data);

        rows = $('#stock-grid tbody tr');
        for(var i = 0; i < rows.length; ++i) {
            cells = rows.eq(i).children('td:not(.button-column)');
            
            if(data[i].companyID != 0) {
                cells.eq(0).addClass('error');
                rows.eq(i).addClass('error-row');
            }
    
            if(data[i].timestamp != 0) {
                cells.eq(2).addClass('error');
                rows.eq(i).addClass('error-row');
            }
            
            if(data[i].open != 0) {
                cells.eq(3).addClass('error');
                rows.eq(i).addClass('error-row');
            }
            
            if(data[i].close != 0) {
                cells.eq(4).addClass('error');
                rows.eq(i).addClass('error-row');
            }
            
            if(data[i].high != 0) {
                cells.eq(5).addClass('error');
                rows.eq(i).addClass('error-row');
            }
            if(data[i].low != 0) {
                cells.eq(6).addClass('error');
                rows.eq(i).addClass('error-row');
            }
            if(data[i].ref != 0) {
                cells.eq(7).addClass('error');
                rows.eq(i).addClass('error-row');
            }
            if(data[i].avg != 0) {
                cells.eq(8).addClass('error');
                rows.eq(i).addClass('error-row');
            }
            if(data[i].ceiling != 0) {
                cells.eq(9).addClass('error');
                rows.eq(i).addClass('error-row');
            }
            if(data[i].floor != 0) {
                cells.eq(10).addClass('error');
                rows.eq(i).addClass('error-row');
            }
            if(data[i].volumeKhopLenh != 0) {
                cells.eq(11).addClass('error');
                rows.eq(i).addClass('error-row');
            }
            if(data[i].volumeAgreement != 0) {
                cells.eq(12).addClass('error');
                rows.eq(i).addClass('error-row');
            }
            if(data[i].valueKhopLenh != 0) {
                cells.eq(13).addClass('error');
                rows.eq(i).addClass('error-row');
            }
            if(data[i].valueAgreement != 0) {
                cells.eq(14).addClass('error');
                rows.eq(i).addClass('error-row');
            }
        }
        $('#stock-grid tbody tr:not(.error-row)').each(function() {$(this).remove();});
    };
</script>